From f27cc5f7c7fee1f85f7681ac81b4c08df1730512 Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Fri, 9 Sep 2005 17:34:40 +0000 Subject: [PATCH] Add remove and list support. Also make all class methods "safe". Signed-off-by: Christian Limpach --- tools/python/xen/xend/xenstore/xstransact.py | 69 ++++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/tools/python/xen/xend/xenstore/xstransact.py b/tools/python/xen/xend/xenstore/xstransact.py index 2e03f3498c..0b8d8612a1 100644 --- a/tools/python/xen/xend/xenstore/xstransact.py +++ b/tools/python/xen/xend/xenstore/xstransact.py @@ -88,40 +88,81 @@ class xstransact: else: raise TypeError + def _remove(self, key): + path = "%s/%s" % (self.path, key) + return xshandle().rm(path) + + def remove(self, *args): + if len(args) == 0: + raise TypeError + for key in args: + self._remove(key) + + def _list(self, key): + path = "%s/%s" % (self.path, key) + return map(lambda x: key + "/" + x, xshandle().ls(path)) + + def list(self, *args): + if len(args) == 0: + raise TypeError + ret = [] + for key in args: + ret.extend(self._list(key)) + return ret + + def Read(cls, path, *args): - t = cls(path) - v = t.read(*args) - t.commit() - return v + while True: + try: + t = cls(path) + v = t.read(*args) + t.commit() + return v + except RuntimeError, ex: + if ex.args[0] == errno.ETIMEDOUT: + pass + raise Read = classmethod(Read) def Write(cls, path, *args, **opts): - t = cls(path) - t.write(*args, **opts) - t.commit() + while True: + try: + t = cls(path) + t.write(*args, **opts) + t.commit() + return + except RuntimeError, ex: + if ex.args[0] == errno.ETIMEDOUT: + pass + raise Write = classmethod(Write) - def SafeRead(cls, path, *args): + def Remove(cls, *args): while True: try: - return cls.Read(path, *args) + t = cls(path) + t.remove(*args) + t.commit() + return except RuntimeError, ex: if ex.args[0] == errno.ETIMEDOUT: pass raise - SafeRead = classmethod(SafeRead) + Remove = classmethod(Remove) - def SafeWrite(cls, path, *args, **opts): + def List(cls, path, *args): while True: try: - cls.Write(path, *args, **opts) - return + t = cls(path) + v = t.list(*args) + t.commit() + return v except RuntimeError, ex: if ex.args[0] == errno.ETIMEDOUT: pass raise - SafeWrite = classmethod(SafeWrite) + List = classmethod(List) -- 2.30.2